/*
 * TMap Designer - A Thematic Map design software
 * Copyright (C) 2006 World Health Organization
 * http://www.who.int
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package who.tmap.toolkit.shape.impl;

import java.util.Comparator;

/**
 * TMap project
 * WHO 2004-2005 
 * A helper class representing a polygon's point
 * 
 * @author stl
 */
@SuppressWarnings("unchecked")
public class PolygonShapePoint implements Cloneable, Comparator {

    int type;
    int originalType;
    
    float x, y;
    // for close path
    float xDest, yDest;
    // an id to define closed polygons
    int polygonId;
    
    void copyValuesFrom( PolygonShapePoint p ) {
        this.type =p.type;
        this.originalType =p.originalType;
        this.x =p.x;
        this.y =p.y;
        this.xDest =p.xDest;
        this.yDest =p.yDest;
        this.polygonId =p.polygonId;
    }  
    
    public Object clone() {
        PolygonShapePoint psp =new PolygonShapePoint();
        
        psp.type =type;
        psp.originalType =originalType;
        psp.x =x;
        psp.y =y;
        psp.xDest =xDest;
        psp.yDest =yDest;
        psp.polygonId =polygonId;
        
        return psp;
    }

    public boolean equals(Object obj) {
        if ( obj instanceof PolygonShapePoint ) {
            PolygonShapePoint psp =(PolygonShapePoint)obj;
            
            return type == psp.type && originalType == psp.originalType
            		&& x == psp.x && y == psp.y 
            		&& xDest == psp.xDest && yDest == psp.yDest
            		&& polygonId == psp.polygonId;
        } else {
            return false;
        }
        
    }

    public int compare(Object o1, Object o2) {
        return o1.equals( o2 ) ? 0 : -1;
    }
    
    public String toString() {
        return "x=" + x + ", y=" + y + ", polygonId=" + polygonId + ", type=" + type + "\n";  
    }
    
    
}
